package com.ccx.coachsite.ui.own;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.ccx.coachsite.R;
import com.ccx.coachsite.bus.ShareInfo;
import com.ccx.coachsite.bus.SoftInfo;

public class OwerShareListAdapter extends OwerAdapterBase<ShareInfo>{
	
	private OwerBaseView superView;
	
	public OwerShareListAdapter(Context context, List<ShareInfo> list) {
		super(context, list);
	}
	
	public void setSuperView(OwerBaseView superView)
	{
		this.superView = superView;
	}
	
	private class OnItemClickListener implements android.widget.AdapterView.OnItemClickListener{
		@Override
		public void onItemClick(AdapterView<?> adapter, View v, int pos, long arg3) {
			if(superView != null)
			{
				Object obj = adapter.getTag();
				if(obj != null)
				{
					List<SoftInfo> lst = (List<SoftInfo>)obj;
					if(pos < lst.size())
					superView.enterApp(lst.get(pos).getId());
				}
			}
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		convertView = mInflater.inflate(R.layout.ower_personal_share_list_item, parent, false);
		holder = new ViewHolder();
		holder.mTitle = (TextView) convertView.findViewById(R.id.ower_share_lab_touser);
		holder.mTime = (TextView) convertView.findViewById(R.id.ower_share_lab_time);
		holder.mShareGrid = (GridView) convertView.findViewById(R.id.ower_share_detail_grid);
		holder.mShareGrid.setOnItemClickListener(new OnItemClickListener());
		convertView.setTag(holder);
		/*
		if(convertView == null) {
			convertView = mInflater.inflate(R.layout.ower_personal_share_list_item, parent, false);
			holder = new ViewHolder();
			holder.mTitle = (TextView) convertView.findViewById(R.id.ower_share_lab_touser);
			holder.mTime = (TextView) convertView.findViewById(R.id.ower_share_lab_time);
			holder.mShareGrid = (GridView) convertView.findViewById(R.id.ower_share_detail_grid);
			holder.mShareGrid.setOnItemClickListener(new OnItemClickListener());
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		*/
		holder.mTitle.setText(mList.get(position).getShareUser());
		holder.mTime.setText(mList.get(position).getShareTime());
		
		OwerFriendDetailItemAdapter gridAdapter = new OwerFriendDetailItemAdapter(mContext, mList.get(position).getShareList());
		holder.mShareGrid.setTag(mList.get(position).getShareList());
		holder.mShareGrid.setAdapter(gridAdapter);
		//holder.mCreator.setText(mList.get(position).getCreator());
		return convertView;
	}
	
	class ViewHolder {
		TextView mTime;
		TextView mTitle;
		GridView mShareGrid;
	}
}
